#include "BaseExplosion.h"

BaseExplosion::BaseExplosion(Ogre::SceneManager * sceneManager):AnimationEvent() {
	systemNameExplosion = 0;
	_mScene = sceneManager;
	_started = false;

}

BaseExplosion::~BaseExplosion(void) {}

void BaseExplosion::prepareEvent() {
	_explosionNode = _mScene->getRootSceneNode()->createChildSceneNode();
	_explosionNode->translate(0,300,-100,Ogre::Node::TS_PARENT);
}

void BaseExplosion::startEvent() {
	_started = true;

	_explosionParticleSystem = _mScene->createParticleSystem("BaseExplosions" + Ogre::StringConverter::toString(systemNameExplosion++), "Base_explosion");
	_explosionNode->attachObject(_explosionParticleSystem);
	_explosionParticleSystem->setRenderQueueGroupAndPriority(Ogre::RENDER_QUEUE_7,3);

	Ogre::ParticleAffector* linearForce = _explosionParticleSystem->getAffector(2);
	linearForce->setParameter("force_vector",Ogre::StringConverter::toString(Ogre::Vector3(0, 0, 200)));

	_explosionParticleSystem = _mScene->createParticleSystem("BaseExplosions" + Ogre::StringConverter::toString(systemNameExplosion++), "Base_explosion");
	_explosionNode->attachObject(_explosionParticleSystem);
	_explosionParticleSystem->setRenderQueueGroupAndPriority(Ogre::RENDER_QUEUE_7,2);

	linearForce = _explosionParticleSystem->getAffector(2);
	linearForce->setParameter("force_vector",Ogre::StringConverter::toString(Ogre::Vector3(0, 0, -200)));

	
	_explosionParticleSystem = _mScene->createParticleSystem("BaseExplosions" + Ogre::StringConverter::toString(systemNameExplosion++), "Base_explosion");
	_explosionNode->attachObject(_explosionParticleSystem);
	_explosionParticleSystem->setRenderQueueGroupAndPriority(Ogre::RENDER_QUEUE_7,5);

	linearForce = _explosionParticleSystem->getAffector(2);
	linearForce->setParameter("force_vector",Ogre::StringConverter::toString(Ogre::Vector3(200, 0, 0)));
	

	_explosionParticleSystem = _mScene->createParticleSystem("BaseExplosions" + Ogre::StringConverter::toString(systemNameExplosion++), "Base_explosion");
	Ogre::SceneNode* explosion4 = _mScene->getRootSceneNode()->createChildSceneNode();
	
	_explosionNode->attachObject(_explosionParticleSystem);
	_explosionParticleSystem->setRenderQueueGroupAndPriority(Ogre::RENDER_QUEUE_7,4);

	linearForce = _explosionParticleSystem->getAffector(2);
	linearForce->setParameter("force_vector",Ogre::StringConverter::toString(Ogre::Vector3(-200, 0, 0)));
	

	_explosionParticleSystem = _mScene->createParticleSystem("BaseExplosions" + Ogre::StringConverter::toString(systemNameExplosion++), "Base_explosion");
	_explosionNode->attachObject(_explosionParticleSystem);
	_explosionParticleSystem->setRenderQueueGroupAndPriority(Ogre::RENDER_QUEUE_7,1);

	linearForce = _explosionParticleSystem->getAffector(2);
	linearForce->setParameter("force_vector",Ogre::StringConverter::toString(Ogre::Vector3(200, 0, 200)));


	_explosionParticleSystem = _mScene->createParticleSystem("BaseExplosions" + Ogre::StringConverter::toString(systemNameExplosion++), "Base_explosion");
	_explosionNode->attachObject(_explosionParticleSystem);
	_explosionParticleSystem->setRenderQueueGroupAndPriority(Ogre::RENDER_QUEUE_7,0);

	linearForce = _explosionParticleSystem->getAffector(2);
	linearForce->setParameter("force_vector",Ogre::StringConverter::toString(Ogre::Vector3(200, 0, -200)));
}

void BaseExplosion::restartEvent() {
	this->prepareEvent();
	this->startEvent();

}

bool BaseExplosion::hasStarted() {
	return _started;
}

void BaseExplosion::update(float deltatime) {
	_explosionNode->translate(0,2000,0,Ogre::Node::TS_PARENT);
}

void BaseExplosion::quit() {
	_explosionNode->detachAllObjects();
	_started = false;
}